Contrasting the LIFO Stack with the FIFO Queue.
- While we have previously examined the Stack, characterized by its LIFO (Last-In, First-Out) principle, our focus now shifts to the Queue.
- A Queue strictly follows the FIFO (First-In, First-Out) principle: the first element to enter is the first to be removed.
- Unlike a Stack's single 'top' pointer, a Queue uses two pointers: front for removal and rear for insertion.
- The core operations are enQueue (add to rear) and deQueue (remove from front).
Stack vs. Queue Properties
| Property | Stack | Queue |
|---|---|---|
| Principle | LIFO (Last-In, First-Out) | FIFO (First-In, First-Out) |
| Access Points | One (Top) | Two (Front & Rear) |
| Add Operation | Push | Enqueue |
| Remove Operation | Pop | Dequeue |